﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SimpleJson;

namespace Dropbox
{
    public partial class DropboxFileLink
    {
        public static DropboxFileLink Load(String json)
        {
            var result = new DropboxFileLink();
            JsonObject jsonObj;
            try
            {

                jsonObj = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(json);
            }
            catch (Exception ex) {
                return result;
            }

            if (jsonObj.ContainsKey("url"))
            {
                result.Url = jsonObj["url"].ToString();
            }
            if (jsonObj.ContainsKey("copy_ref"))
            {
                result.CopyRef = jsonObj["copy_ref"].ToString();
            }
            if (jsonObj.ContainsKey("expires"))
            {
                result.ExpiresString = jsonObj["expires"].ToString();
                DateTime date;
                if (DateTime.TryParse(result.ExpiresString, out date))
                    result.Expires = date;
            }

            return result;
        }

        public String Url { get; set; }
        public String CopyRef { get; set; }
        public String ExpiresString { get; set; }
        public DateTime Expires { get; set; }
    }
}
